package net.zoneland.zrdp.web.controller.system;

import net.zoneland.zrdp.common.annotation.Anonymous;
import net.zoneland.zrdp.common.core.domain.AjaxResult;
import net.zoneland.zrdp.common.core.domain.vo.BaseInfo;
import net.zoneland.zrdp.system.service.mapstruct.BaseInfoConverter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import net.zoneland.zrdp.common.config.ZonevueConfig;

import javax.annotation.Resource;
import java.text.MessageFormat;


/**
 * 首页
 *
 * @author zonevue
 */
@RestController
public class SysIndexController {
    /** 系统基础配置 */
    @Resource
    private ZonevueConfig zonevueConfig;

    /**
     * 访问首页，提示语
     */
    @RequestMapping("/version")
    @Anonymous
    public String index() {
        return MessageFormat.format("欢迎使用{0}后台系统，当前版本：v{1}，请通过前端地址访问。", zonevueConfig.getName(), zonevueConfig.getVersion());
    }

    /**
     * 获取系统基本信息：如果开启sso 认证的话，获取cookie调用尝试获取用户信息
     * @return 基本信息json
     */
    @GetMapping("/getAppBaseInfo")
    public AjaxResult getAppBaseInfo() {
        final BaseInfo baseInfo = BaseInfoConverter.INSTANCE.zoneVueConfigToBaseinfo(zonevueConfig);
        final AjaxResult ajax = AjaxResult.success();
        ajax.put("baseInfo", baseInfo);
        return ajax;
    }
}
